<?php 

// 控制基类
class Controller extends Smarty
{
    // 初始化配置
    public function __construct()
    {
        $this->setTemplateDir('./views')
                ->setCompileDir('./runtime/views_c')
                ->setConfigDir('./configs')
                ->setCacheDir('./runtime/caches');
        // 配置 模板变量的定界符  {{ }} 
        $this->left_delimiter = LEFT_D;
        $this->right_delimiter = RIGHT_D;
        // 配置 缓存控制 (开启缓存/缓存时间)
        $this->caching = CACHING;// 开启缓存
        $this->cache_lifetime = CACHE_LIFETIME;// 缓存时间 10s
    }

    public function __call($fun, $params)
    {
        header("HTTP/1.0 404 not found");
        echo '<h1>404 Not Found 控制器</h1>';
        exit;
    }

    /**
     * 跳转重定向
     * @param  str $message 提示信息
     * @param  str $url     跳转地址
     * @return null
     */
    public function redirect($message, $url = null)
    {
        echo "<script>alert('{$message}')</script>";
        if (empty($url)) {
            echo "<script>history.back()</script>";
        } else {
            echo "<script>location.href='{$url}'</script>";
        }
    }
}



